#!/bin/sh
#================
# find out the new svn repos,and svnadmin create it and svnsync.xuejiang
# 6 5 * * * ads (sh /home/ads/Shell/syninit.sh | tee -a /home/ads/syn.log)
#================
SOURCE_HOST="svn.example.com"
des_host="10.232.1*.*"
DES_DIR_arr="/opt/svnroot /opt/svnroot/wl"
notallowed="test*|^wl$"
for DES_DIR in $DES_DIR_arr 
do
if [ -e ~/initsync.pid ];then
	echo "init svnsync is running...."
	exit
fi
touch ~/initsync.pid
cd ${DES_DIR}
case ${DES_DIR} in
        /opt/svnroot)
                svnnote='svn'
		dot=''
                ;;
        /opt/svnroot/wl)
                svnnote='wireless'
		dot='_wl'
                ;;
        *) 
                svnnote='repos'
                ;;
esac
rm ~/syn_err.log
for repos in `cat ~/repos${dot}.log`
do
	if [ ! -d "${DES_DIR}/$repos" ]
	then
		echo $repos | grep -E "$notallowed"
		if [ $? == 0 ];then
			continue
		fi
		echo "======found new repos,begin create $repos===="
		svnadmin create $repos --pre-1.6-compatible
		if [ $? != 0 ];then
			echo "Error:$repos create failed!" | tee -a ~/syn_err.log
			continue
		fi
		touch ~/$repos.pid
		echo "====change $repos hooks mod to 755 ========"
		cp  /opt/svnroot/conf/sample_svn/hooks/pre-revprop-change $repos/hooks/
		echo "=====begin cp uuid $repos========"
	#	svnsync sync "file://${DES_DIR}/$repos" 2>>~/syn_err.log
		cp -f /home/ads/data/${dot}/${repos}uuid $DES_DIR/$repos/db/uuid
		echo "=====begin svnsync init $repos ======"
		svnsync init "http://$des_host/$svnnote/$repos" "file://${DES_DIR}/$repos" --username svnsync --password *** 2>>~/syn_err.log
		rm -f  ~/$repos.pid
	fi	
done
echo "sync init end"
if [ -s ~/syn_err.log ]
then
	cat ~/syn_err.log | mail -s "svnsync error Report on `date +%Y%m%d`" xuejiang@taobao.com
fi
rm -f ~/initsync.pid
done
